﻿@{Layout = null;}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="renderer" content="webkit|ie-comp|ie-stand" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link href="~/assets/css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/Content/style.css" />
    <link href="~/assets/css/codemirror.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/assets/css/ace.min.css" />
    <link rel="stylesheet" href="~/font/css/font-awesome.min.css" />
    <link rel="stylesheet" href="~/layui/css/layui.css" />
    <!--[if lte IE 8]>
      <link rel="stylesheet" href="~/assets/css/ace-ie.min.css" />
    <![endif]-->
    <script src="~/Scripts/jquery-1.9.1.min.js"></script>
    <script src="~/layui/layui.js" type="text/javascript"></script>
    <script src="~/assets/js/bootstrap.min.js"></script>
    <script src="~/assets/js/typeahead-bs2.min.js"></script>
    <script src="~/assets/js/jquery.dataTables.min.js"></script>
    <script src="~/assets/js/jquery.dataTables.bootstrap.js"></script>
    <script src="~/assets/layer/layer.js"></script>
    <script src="~/assets/laydate/laydate.js" type="text/javascript"></script>
    <title>管理权限</title>
</head>

<body>
    <div class="margin clearfix">
        <div class="border clearfix">

            <span class="l_f">
                <a href="javascript:ovid()" id="add_page" class="btn btn-warning" onclick="add_article_sort()"><i class="fa fa-plus"></i> 添加分类</a>
                <a href="javascript:ovid()" id="DelRole" class="btn btn-danger"><i class="fa fa-trash"></i> 批量删除</a>
            </span>
            <span class="r_f">共：<b>5</b>类</span>
        </div>
        <!--分类类表-->
        <div class="article_sort_list">
            <table class="layui-hide" id="test" lay-filter="demo"></table>
            <script type="text/html" id="barDemo">

                <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>
            <script type="text/html" id="switchTpl">
                <input type="checkbox" id="{{d.Id}}" name="IsEnable" value="{{d.IsEnable}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="sexDemo" {{ d.IsEnable == '1' ? 'checked' : ' ' }} />
            </script>
        </div>

    </div>
    <div id="add_administrator_style" class="add_menber" style="display:none">
        <form id="form-admin-add">
            <input type="hidden" value="" placeholder=" " id="ID" name="ID" nullmsg="" />
            <div class="form-group">
                <label class="form-label"><span class="c-red">*</span>管理员权限：</label>
                <div class="formControls">
                    <input type="text" class="input-text" value="" placeholder="" id="AdminRole" name="AdminRole" datatype="*2-16" nullmsg="权限名不能为空" />
                </div>
                <div class="col-4"> <span class="Validform_checktip"></span></div>
            </div>
            <div class="form-group">
                <label class="form-label">描述：</label>
                <div class="formControls">
                    <textarea name="Context" cols="" rows="" class="textarea" placeholder="说点什么...100个字符以内" dragonfly="true" onkeyup="checkLength(this);"></textarea>
                    <span class="wordage">剩余字数：<span id="sy" style="color:Red;">100</span>字</span>
                </div>
                <div class="col-4"> </div>
            </div>
            <div>
                <input class="btn btn-primary radius" type="button" id="UpdateRole" value="&nbsp;&nbsp;提交&nbsp;&nbsp;" />
            </div>
        </form>
    </div>
    <!--添加文章分类图层-->
    <div id="addsort_style" style="display:none" class="article_style">
        <div class="add_content" id="form-article-add">
            <ul>
                <li class="clearfix Mandatory">
                    <label class="label_name"><i>*</i>分类名称</label>
                    <span class="formControls w_txt"><input name="分类名称" type="text" id="form-field-1" class="col-xs-7 col-sm-5 " /></span>
                </li>
                <li class="clearfix">
                    <label class="label_name">排序</label>
                    <span class="formControls w_txt"><input name="排序" type="text" id="form-field" value="0" class="col-xs-7 col-sm-2 " /></span>
                </li>
                <li class="clearfix">
                    <label class="label_name">状态</label>
                    <span class="formControls w_txt"><input name="状态" type="text" id="form-tai" value="0" class="col-xs-7 col-sm-2 " /></span>
                </li>
                <li class="clearfix">
                    <label class="label_name">简介</label>
                    <span class="formControls w_txt"><textarea name="权限描述" class="form-control" id="form_textarea" placeholder="" onkeyup="checkLength(this);"></textarea><span style=" margin-left:10px;">剩余字数：<span id="sy" style="color:Red;">200</span>字</span></span>
                </li>
                <li class="clearfix">
                    <label class="label_name">父级ID</label>
                    <span class="formControls w_txt"><input name="父级ID" type="text" id="ParentId" value="0" class="col-xs-7 col-sm-2 " /></span>
                </li>
                <li class="clearfix Mandatory">
                    <label class="label_name">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</label>
                    <input name="提交" type="button" id="btn" value="提交" class="col-xs-7 col-sm-5 " />
                </li>
            </ul>
        </div>
    </div>
    <!--修改文章分类图层-->
    <div id="addsort_update" style="display:none" class="article_style">
        <div class="add_content" id="form-article-add">
            <ul>
                <li class="clearfix Mandatory">
                    <label class="label_name"><i>*</i>分类名称</label>
                    <span class="formControls w_txt"><input name="分类名称" type="text" id="name" class="col-xs-7 col-sm-5 " /></span>
                </li>
                <li class="clearfix">
                    <label class="label_name">排序</label>
                    <span class="formControls w_txt"><input name="排序" type="text" id="sort" class="col-xs-7 col-sm-2 " /></span>
                </li>
                <li class="clearfix">
                    <label class="label_name">状态</label>
                    <span class="formControls w_txt"><input name="状态" type="text" id="IsEnable" class="col-xs-7 col-sm-2 " /></span>
                </li>
                <li class="clearfix">
                    <label class="label_name">简介</label>
                    <span class="formControls w_txt"><textarea name="权限描述" class="form-control" id="remotee" placeholder="" onkeyup="checkLength(this);"></textarea><span style=" margin-left:10px;">剩余字数：<span id="sy" style="color:Red;">200</span>字</span></span>
                </li>
                <li class="clearfix">
                    <label class="label_name">父级ID</label>
                    <span class="formControls w_txt"><input name="父级ID" type="text" id="PID" class="col-xs-7 col-sm-2 " /></span>
                </li>
                <li class="clearfix Mandatory">
                    <label class="label_name">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</label>
                    <input name="提交" type="button" id="submit" value="提交" class="col-xs-7 col-sm-5 " />
                </li>
            </ul>
        </div>
    </div>




</body>
</html>

<!--显示-->
<script type="text/javascript">
    layui.use('table', function () {
        var table = layui.table;
        var form = layui.form;
        table.render({
            elem: '#test'      //跟表格id一一对应
            , url: '/Module/GetModulePageList'   //控制器对应的方法
            , cols: [[
                { field: 'Id', width: 180, title: '编号', sort: true }
                , { field: 'SortId', width: 180, title: '排序', sort: true }
                , { field: 'Name', width: 180, title: '分类名称', sort: true }
                , { field: 'Remark', width: 180, title: '简介', sort: true }
                , { field: 'IsEnable', width: 180,templet: '#switchTpl', title: '状态', unresize: true }
                , { title: '操作', fixed: 'right', width: 278, align: 'center', toolbar: '#barDemo' }
            ]]
            , page: true
            , Id: 'Id'
        });

        //状态
            form.on('switch(sexDemo)', function (obj) {
                var tip = "启用";
                var id = this.id;
                var IsEnable = this.value;

                if (this.value === "1") {
                    tip = "停用";
                    IsEnable = 0;
                } else {
                    IsEnable = 1;
                }
               
                layer.confirm('真的要' + tip + '吗', function (index) {
                    $.ajax({
                        url: "/Module/UpdateZt?id=" +id +"&isEnable=" + IsEnable,
                        type: "post",
                        success: function (result) {
                            if (result.Sueess) {
                                layer.msg(tip + '失败！');
                            } else {
                                
                                layer.msg(tip + '成功！', { title: '提示框', icon: 1, time: 2000 }, function () { window.location.reload() });
                            }
                        }
                    })
                })
            });

        //监听行工具事件
        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            if (obj.event == 'edit') {
                $("#name").val(data.Name);
                $("#sort").val(data.SortId);
                $("#remotee").val(data.Remark);
                $("#PID").val(data.ParentId);
                $("#IsEnable").val(data.IsEnable);

                layer.open({
                    type: 1,
                    title: '修改信息',
                    area: ['490px', ''],
                    shadeClose: false,
                    content: $('#addsort_update'),
                });
                $("#submit").click(function () {
                    var role = {};
                    role.Id = data.Id;
                    role.Name = $("#name").val();
                    role.Remark = $("#remotee").val();
                    role.IsEnable = $("#IsEnable").val();
                    role.SortId = $("#sort").val();
                    role.ParentId = $("#PID").val();
                    $.ajax({
                        type: "post",
                        data: role,
                        url: "/Module/UpdateModule",
                        success: function (result) {
                            if (result.Success) {
                                layer.alert('修改成功！', {
                                    title: '提示框',
                                    icon: 1,
                                });
                            } else {
                                layer.alert('修改失败！', {
                                    title: '提示框',
                                    icon: 1,
                                });
                            }
                        },
                    });
                });
            } else if (obj.event == 'del') {
                layer.confirm('确认要删除吗？', { icon: 0, }, function (index) {
                    $.ajax({
                    type: "post",
                    url: "/Module/DelModule?Id=" + data.Id,
                    success: function (result) {
                        if (result.Success) {
                             layer.msg("删除成功", { icon: 1, time: 1000 }, function () {
                             location.reload();//刷新页面
                            })
                             , function () { window.location.reload() }
                        } else {
                            layer.alert('删除失败！', {
                                title: '提示框',
                                icon: 1,
                            });
                        }
                    },
                });
                });
                
                //}
            }
        });

        $("#ben").click(function () {
            var checkStatus = table.checkStatus('Id');
            var data = checkStatus.data;
            var codeId = "";
            if (data.length == 0) {
                layer.msg('请选中一行', {
                    title: '提示框',
                    icon: 0,
                    time: 2000
                });
                return;
            };


            $.ajax({
                type: "post",
                url: "/Module/BactchDelete?codeId=" + codeId,
                success: function (result) {
                    if (result.Sueess) {
                        location.reload();//刷新
                    }
                },
            });
        });

        //添加
        $("#btn").click(function () {
            var module = {};
            module.Name = $("#form-field-1").val();
            module.SortId = $("#form-field").val();
            module.Remark = $("#form_textarea").val();
            module.IsEnable = $("#form-tai").val();
            module.ParentId = $("#ParentId").val();
            var name = module.Name;

            $.ajax({
                type: "post",
                data: module,
                url: "/Module/SelModule",
                success: function (result) {
                    if (result.Success) {
                        layer.msg('组名已存在，不能添加！', {
                            title: '提示框',
                            icon: 1,
                            time: 2000
                        });
                    } else {
                        $.ajax({
                            type: "post",
                            data: module,
                            url: "/Module/AddModule",
                            success: function (result) {
                                if (result.Success) {
                                    layer.msg('添加成功！', {
                                        title: '提示框',
                                        icon: 1,
                                        time: 2000
                                    }
                                     , function () { window.location.reload() })
                                } else {
                                    layer.alert('添加失败！', {
                                        title: '提示框',
                                        icon: 1,
                                    });
                                }
                            },
                        });
                    }
                },
            });
        });
    });
</script>




<script>

    $(function () {
        var oTable1 = $('#sample-table').dataTable({
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": true,//状态保存
            "aoColumnDefs": [
                //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
                { "orderable": false, "aTargets": [0, 2, 3, 4, 6, 7,] }// 制定列不参与排序
            ]
        });
        $('table th input:checkbox').on('click', function () {
            var that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function () {
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });
        });
    })
    /**添加分类**/
    function add_article_sort(index) {
        layer.open({
            type: 1,
            title: '添加文章分类',
            maxmin: true,
            shadeClose: true, //点击遮罩关闭层
            area: ['600px', ''],
            content: $('#addsort_style'),
            yes: function (index, layero) {
                var num = 0;
                var str = "";
                $(".Mandatory input[type$='text']").each(function (n) {
                    if ($(this).val() == "") {

                        layer.alert(str += "" + $(this).attr("name") + "不能为空！\r\n", {
                            title: '提示框',
                            icon: 0,
                        });
                        num++;
                        return false;
                    }
                });
                if (num > 0) { return false; }
                else {
                    layer.alert('添加成功！', {
                        title: '提示框',
                        icon: 1,
                    });
                    layer.close(index);
                }

            }
        })
    }

    /*修改*/
    $("#addsort_update").hide();

    /*文章-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', { icon: 0, }, function (index) {
            $(obj).parents("tr").remove();
            layer.msg('已删除!', { icon: 1, time: 1000 });
        });
    }

</script>


